package framework.task;

import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.Serializable;

/**
 * @Name: Task
 * @Description:
 * @Author: colfish
 * @Date: 2021/5/11 10:29
 * 好好学习，天天向上！
 */
public abstract class Task implements Serializable {

    private static final long serialVersionUID = -8545975493448426468L;
    private final Logger logger = LogManager.getLogger(Task.class);
    protected Behaviour behaviour;
    protected String myName;
    protected Agent myAgent;

    public Task(){
        this.myName = this.getClass().getSimpleName();
    }


    public void onStart(){

    }

    public void doTask(){
        logger.info("Task " + myName + " start running!");
        myAgent.addBehaviour(behaviour);
    }

    public boolean done(){
        logger.info("Task " + myName + " done!");
        return behaviour.done();
    }

    public int onEnd(){
        return behaviour.onEnd();
    }

    public void block(){
        behaviour.block();
    }

    public void restart(){
        behaviour.restart();
    }


    public Behaviour getBehaviour() {
        return behaviour;
    }

    public String getTaskName() {
        return myName;
    }

    public void setTaskName(String myName) {
        this.myName = myName;
    }

    public Agent getAgent() {
        return myAgent;
    }

    public void setAgent(Agent myAgent) {
        this.myAgent = myAgent;
    }
}
